﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Windows;
//using System.Windows.Media;

//namespace Hotel.UI.Helpers
//{
//    /// <summary>
//    /// Helper methods to go through the logical and the visual tree
//    /// </summary>
//    public class TreeHelper1
//    {
//        /// <summary>
//        /// Determiner whether an element is the logical ancestor of another item
//        /// </summary>
//        /// <param name="parent">Parent element</param>
//        /// <param name="source">Child element</param>
//        /// <returns>True if the Child element has the Parent element as its parent in the logical tree</returns>
//        public static bool IsLogicalAncestorOf(FrameworkElement parent, FrameworkElement source)
//        {
//            if (parent == source)
//            {
//                return true;
//            }

//            FrameworkElement current = source;
//            while (current != null && current.Parent != null)
//            {
//                if (current.Parent == parent)
//                {
//                    return true;
//                }

//                current = current.Parent as FrameworkElement;
//            }

//            return false;
//        }



//        /// <summary>
//        /// Find all visual children of a given type
//        /// </summary>
//        /// <typeparam name="T">Type of the children to find</typeparam>
//        /// <param name="obj">Source dependency object</param>
//        /// <returns>A list of T objects that are visual children of the source dependency object</returns>
//        public static List<T> FindVisualChildren<T>(DependencyObject obj) where T : DependencyObject
//        {
//            List<T> matches = new List<T>();
//            return FindVisualChildren(obj, matches);
//        }

//        /// <summary>
//        /// Find the first visual child of a given type
//        /// </summary>
//        /// <typeparam name="T">Type of the visual child to retrieve</typeparam>
//        /// <param name="obj">Source dependency object</param>
//        /// <returns>First child that matches the given type</returns>
//        public static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
//        {
//            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
//            {
//                DependencyObject child = VisualTreeHelper.GetChild(obj, i);
//                if (child != null && child is T)
//                {
//                    return (T)child;
//                }
//                else
//                {
//                    T childOfchild = FindVisualChild<T>(child);
//                    if (childOfchild != null)
//                    {
//                        return childOfchild;
//                    }
//                }
//            }

//            return null;
//        }

//        /// <summary>
//        /// Find the first visual ancestor of a given type
//        /// </summary>
//        /// <typeparam name="T">Type of the ancestor</typeparam>
//        /// <param name="element">Source visual</param>
//        /// <returns>First ancestor that matches the type in the visual tree</returns>
//        public static T FindVisualAncestor<T>(UIElement element) where T : class
//        {
//            while (element != null && !(element is T))
//            {
//                element = (UIElement)VisualTreeHelper.GetParent(element);
//            }

//            return element as T;
//        }

//        /// <summary>
//        /// Find all visual children of a given type
//        /// </summary>
//        /// <typeparam name="T">Type of the children to find</typeparam>
//        /// <param name="obj">Source dependency object</param>
//        /// <param name="matches">List of matches</param>
//        /// <returns>A list of T objects that are visual children of the source dependency object</returns>
//        private static List<T> FindVisualChildren<T>(DependencyObject obj, List<T> matches) where T : DependencyObject
//        {
//            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
//            {
//                DependencyObject children = VisualTreeHelper.GetChild(obj, i);
//                if (children != null && children is T)
//                {
//                    matches.Add((T)children);
//                }
//                FindVisualChildren(children, matches);
//            }

//            return matches;
//        }
//    }
//}
